package org.itcast.travel.controller;

import org.itcast.travel.pojo.PageBean;
import org.itcast.travel.pojo.Place;
import org.itcast.travel.pojo.PlaceQueryParam;
import org.itcast.travel.pojo.Result;
import org.itcast.travel.service.PlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/place")
public class PlaceController {
    @Autowired
    private PlaceService placeService;
    /*
    管理端 分页查询并且条件查询
     */
    @GetMapping
    public Result placePage(PlaceQueryParam placeQueryParam){
        PageBean placePageBean = placeService.placepage(placeQueryParam);
        return Result.success(placePageBean);
    }
    /**
     * 景点删除 批量删除 + 单独删除
     */
    @DeleteMapping("{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        placeService.deletByIds(ids);
        return Result.success();
    }

    /**
     * 增加景点
     */
    @PostMapping
    public Result addPlace(@RequestBody Place place){
        placeService.add(place);
        return Result.success();
    }

    /**
     * 修改回显
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Place placeInfo = placeService.getByid(id);
        return Result.success(placeInfo);
    }

    /**
     * 修改景点
     */
    @PutMapping
    public Result updatePlace(@RequestBody Place place){
        placeService.update(place);
        return Result.success();
    }

}
